<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>随机图文</title>
  <style>
    body {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      height: 100vh;
      margin: 0;
      background: #f7f7f7;
      font-family: sans-serif;
    }
    img {
      max-width: 90%;
      max-height: 50vh;
      border-radius: 12px;
      box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    }
    .text {
      margin-top: 15px;
      font-size: 20px;
      font-weight: bold;
      text-align: center;
      color: #333;
      padding: 0 20px;
    }
    button {
      margin-top: 20px;
      padding: 10px 20px;
      font-size: 18px;
      border: none;
      border-radius: 8px;
      background: #4CAF50;
      color: white;
    }
  </style>
</head>
<body>
  <img id="randomImage" src="" alt="随机图片">
  <div id="randomText" class="text"></div>
  <button onclick="showRandomItem()">换一张</button>

  <script>
    // 图片 + 文本数组
    const items = [
      { img: "img1.jpg", text: "第一张图的描述文字" },
      { img: "img2.jpg", text: "第二张图的描述文字" },
      { img: "img3.jpg", text: "第三张图的描述文字" }
    ];

    function showRandomItem() {
      const randomIndex = Math.floor(Math.random() * items.length);
      document.getElementById("randomImage").src = items[randomIndex].img;
      document.getElementById("randomText").textContent = items[randomIndex].text;
    }

    showRandomItem(); // 页面加载时显示一张
  </script>
</body>
</html>
